package Actions;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class degreeDiscpAction extends Action {
	
	private FormFile myFile = null;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		forms.degreeform a = (forms.degreeform) form;
		
		request.getSession().setAttribute("discp", a.getDiscp());
		request.getSession().setAttribute("Dmonth", a.getDmonth());
		request.getSession().setAttribute("Dyear", a.getDyear());
		request.getSession().setAttribute("GPA", a.getGpa());
		request.getSession().setAttribute("title", a.getTitle());
		
		// Process the FormFile
		myFile = a.getFile();

		String fileName = myFile.getFileName();
		int fileSize = myFile.getFileSize();

		request.getSession().setAttribute("filename", fileName);
		request.getSession().setAttribute("filesize", fileSize);
		
		a.setFileName(fileName);
		a.setFileSize(fileSize);
	
		try {
			a.setMyFile(myFile.getInputStream());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

    	return mapping.findForward("degreesuccess");
	}
}
